
package edi.entities;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.Where;
import org.joda.time.DateTime;
import org.springframework.data.domain.Auditable;

/**
 *
 * @author Kamil
 */
@Entity
@Table(name = "T_USERS")
@Where(clause = "USR_AUDIT_RD IS NULL")
public class UserEntity implements Auditable<Long, Long>, Serializable {

    private static final long serialVersionUID = 4169905761804555798L;

    @Id
    @SequenceGenerator(name = "user_sequence", sequenceName = "S_USR_ID", allocationSize = 1)
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "user_sequence")
    @Column(name = "USR_ID")
    private Long usrId;

    @Column(length = 30, nullable = false, name = "USR_LOGIN", unique = true)
    private String usrLogin;

    @Column(length = 100, nullable = false, name = "USR_PASSWORD")
    private String usrPassword;

    @Column(length = 50, name = "USR_FIRST_NAME")
    private String usrFirstName;

    @Column(length = 50, name = "USR_LAST_NAME")
    private String usrLastName;

    @Column(length = 1, name = "USR_STATUS")
    private String usrStatus;
    
    @OneToMany(mappedBy="udeUser", fetch = FetchType.EAGER)
    private List<DepartmentUserEntity> userDeps = new ArrayList<>();
    
    
    @Column(name = "USR_AUDIT_CD")
    @Type(type="org.jadira.usertype.dateandtime.joda.PersistentDateTime") 
    private DateTime createdDate;
    
    @Column(name = "USR_AUDIT_CU")
    private Long createUser;
    
    @Column(name = "USR_AUDIT_MD")
    @Type(type="org.jadira.usertype.dateandtime.joda.PersistentDateTime") 
    private DateTime modifiedDate;
    
    @Column(name = "USR_AUDIT_MU")
    private Long modifiedUser;
    
    @Column(name = "USR_AUDIT_RD")
    @SuppressWarnings("unused")
    @Type(type="org.jadira.usertype.dateandtime.joda.PersistentDateTime") 
    private DateTime removeDate;
    
    @Column(name = "USR_AUDIT_RU")
    @SuppressWarnings("unused")
    private Long removeUser;

    
    public Long getUsrId() {
        return usrId;
    }

    public String getUsrLogin() {
        return usrLogin;
    }

    public void setUsrLogin(String usrLogin) {
        this.usrLogin = usrLogin;
    }

    public String getUsrPassword() {
        return usrPassword;
    }

    public void setUsrPassword(String usrPassword) {
        this.usrPassword = usrPassword;
    }

    public String getUsrFirstName() {
        return usrFirstName;
    }

    public void setUsrFirstName(String usrFirstName) {
        this.usrFirstName = usrFirstName;
    }

    public String getUsrLastName() {
        return usrLastName;
    }

    public void setUsrLastName(String usrLastName) {
        this.usrLastName = usrLastName;
    }

    public String getUsrStatus() {
        return usrStatus;
    }

    public void setUsrStatus(String usrStatus) {
        this.usrStatus = usrStatus;
    }

    public List<DepartmentUserEntity> getUserDeps() {
        return userDeps;
    }

    public void setUserDeps(List<DepartmentUserEntity> userDeps) {
        this.userDeps = userDeps;
    }

    
    @Override
    public boolean isNew() {
        return (usrId == null);
    }
    
     @Override
     public int hashCode() {
        return HashCodeBuilder.reflectionHashCode(this);
     }

     @Override
     public boolean equals(Object o) {
        return EqualsBuilder.reflectionEquals(this, o);
     }

     @Override
     public String toString() {
        return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
     }
    
     @Override
    public Long getCreatedBy() {
      return createUser;
    }
    
    @Override
    public void setCreatedBy(Long u) {
        createUser = u;
    }

    @Override
    public org.joda.time.DateTime getCreatedDate() {
    return createdDate;
    }

    @Override
    public void setCreatedDate(org.joda.time.DateTime dt) {
       createdDate = dt;
    }

    @Override
    public Long getLastModifiedBy() {
        return modifiedUser;
    }

    @Override
    public void setLastModifiedBy(Long u) {
       modifiedUser = u;
    }

    @Override
    public org.joda.time.DateTime getLastModifiedDate() {
        return modifiedDate;
    }

    @Override
    public void setLastModifiedDate(org.joda.time.DateTime dt) {
        modifiedDate = dt;
    }
    
    public void setRemoveDate(org.joda.time.DateTime dt) {
        removeDate = dt;
    }
           
    public void setRemovedBy(Long u) {
       removeUser = u;
    }

    @Override
    public Long getId() {
        return usrId;
    }
    
}
